package com.zhonghui.modlules.user.controller;

import com.zhonghui.common.bean.LocalUser;
import com.zhonghui.common.eshopConstant.SystemConfigConstants;
import com.zhonghui.common.eshopDomain.ShopUser;
import com.zhonghui.common.eshopUtil.ApiResult;
import com.zhonghui.modlules.shop.eshopService.SystemConfigService;
import com.zhonghui.modlules.user.eshopParam.UserExtParam;
import com.zhonghui.modlules.user.eshopService.UserExtractService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.Map;

@Slf4j
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(value = "用户提现", tags = "用户:用户提现", description = "用户提现")
public class UserExtractController {

    private final UserExtractService userExtractService;
    private final SystemConfigService systemConfigService;

    @ApiOperation(value = "提现参数",notes = "提现参数")
    @GetMapping("/extract/bank")
    public ApiResult<Object> bank(){
        ShopUser shopUser = LocalUser.getUser();
        Map<String, Object> map = new LinkedHashMap<>();
        map.put("commissionCount",shopUser.getBrokeragePrice());
        map.put("minPrice",systemConfigService.getData(SystemConfigConstants.USER_EXTRACT_MIN_PRICE));
        return ApiResult.ok(map);
    }

    @ApiOperation(value = "用户提现",notes = "用户提现")
    @PostMapping("/extract/cash")
    public ApiResult<String> extractCash(@Validated @RequestBody UserExtParam userExtParam){
        ShopUser shopUser = LocalUser.getUser();
        userExtractService.userExtract(shopUser,userExtParam);
        return ApiResult.ok("申请提现成功");
    }
}
